package com.gxust.mapper;

import com.gxust.pojo.Address;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AddressMapper {
    @Insert("INSERT INTO address (userId, phoneNumber, recipientName, address) " +
            "VALUES (#{userId}, #{phoneNumber}, #{recipientName}, #{address})")
    @Options(useGeneratedKeys = true, keyProperty = "addressId")
    void insertAddress(Address address);


    @Delete("delete from address where AddressID = #{id}")
    void deleteById(Integer id);

    @Update("UPDATE address " +
            "SET phoneNumber = #{phoneNumber}, recipientName = #{recipientName}, address = #{address} " +
            "WHERE addressId = #{addressId}")
    void update(Address address);

    //根据addressID查询
    @Select("select * from address where AddressID = #{id}")
    Address getAddressById(Integer id);

    //根据UserID查询
    @Select("select * from address where UserID = #{userId}")
    List<Address> getAddressByUserId(Integer userId);
}
